<include file="Public:header"/>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<!-- form 样式 -->
<link href="__STATIC__/form/style.css" rel='stylesheet' type='text/css' />
<link href="__STATIC__/form/font-awesome.css" rel="stylesheet"> 

<link href="__STATIC__/form/animate.css" rel="stylesheet" type="text/css" media="all">
<link href="__STATIC__/form/add.css" rel="stylesheet" type="text/css" media="all">


<div class="form-grids row widget-shadow" data-example-id="basic-forms"> 

	<div class="form-body">
			<div class="form-group">
				<label for="exampleInputEmail1" class="col-md-2 control-label">姓名</label>
				<div class="col-md-10">
					<input type="text" id='truename' name='truename' class="form-control" id="exampleInputEmail1" value="{$info.truename}" placeholder="请输入姓名">
				</div>
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1" class="col-md-2 control-label">联系方式</label>
				<div class="col-md-10">
					<input type="text" id='mobile' name='mobile' class="form-control" id="exampleInputEmail1" value="{$info.mobile}" placeholder="请输入联系方式">
				</div>
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1" class="col-md-2 control-label">账号</label>
				<div class="col-md-10">
					<input type="text" id='name' name='name' class="form-control" id="exampleInputEmail1" value="{$info.name}" placeholder="请输入账号">
				</div>
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1" class="col-md-2 control-label">密码</label>
				<div class="col-md-10">
					<input type="text" id='password' name='password' class="form-control" id="exampleInputEmail1" value="{$info.password}" placeholder="请输入密码">
				</div>
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1" class="col-md-2 control-label">角色分配</label>
				<div class="col-md-10">
					<select name="role_id" class='role_id form-control' style="width:30%;" value="{$info.role_id}">
						<option>请选择</option>
						<?php foreach($roles as $k=>$val):?>
							<option value={$val['id']}>{$val['name']}</option>
						<?php endforeach;?>
					</select>
				</div>
				<!-- <input type='hidden' name='wuyefei' class='wuyefei'> -->
			</div>
			<script>
			    var data=$('.role_id').attr('value');
			    var val=$('.role_id option');
			    for(i=0;i<val.length;i++){
			        if($(val[i]).attr('value')==data){
			             $(val[i]).attr('selected',true);
			        }
			    }
			</script>
			<div class="form-group">
				<div class="col-md-offset-2 col-md-10">
					<input type="hidden" class="admin_id" value="{$info.id}">
					<button type="submit" class="sub" class="btn btn-primary">提交</button>
				</div>
			</div>
	</div>
</div>
<script src="__STATIC__/news/js/jquery.min.js?v=2.1.4"></script>
<script src="__STATIC__/components/layui/layui/layui.all.js"></script>
<script type="text/javascript">
	$(".sub").click(function(){
		var admin_id = $('.admin_id').val();
		var truename = $('#truename').val();
		if(truename == ''){
			alert('请输入职工姓名');return false;
		}
		var mobile = $('#mobile').val();
		if(mobile == ''){
			alert('请输入联系方式');return false;
		}
		var name = $('#name').val();
		if(name == ''){
			alert('请输入账号');return false;
		}
		var password = $('#password').val();
		if(password == ''){
			alert('请输入密码');return false;
		}
		var role_id=$(".role_id option:selected").val();
		if(role_id == "请选择"){
			alert('请分配角色');return false;
		}
		if(admin_id > 0){
			//修改
			$.ajax({
			    url:"{:U('System/edit_admin')}",
			    data:{admin_id:admin_id,truename:truename,mobile:mobile,name:name,password:password,role_id:role_id},
			    type:"POST",
			    dataType:"json",
			    success:function(ret){
			        if(ret.value==2){
			            layer.msg(ret.msg,{time:3000});
			            layer.close('layer');
			        }else{
			            layer.msg(ret.msg,{time:3000});
			        }
			    }
			})
		}else{
			//新增
			$.ajax({
			    url:"{:U('System/add_admin')}",
			    data:{truename:truename,mobile:mobile,name:name,password:password,role_id:role_id},
			    type:"POST",
			    dataType:"json",
			    success:function(ret){
			        if(ret.value==2){
			            layer.msg(ret.msg,{time:3000});
			            layer.close('layer');
			        }else{
			            layer.msg(ret.msg,{time:3000});
			        }
			    }
			})
		}
	})

</script>

<include file="Public:footer"/>